<!DOCTYPE html>
<html lang="en">

<include file="CommonSidebar:common-head"/>
<link href="__PUBLIC__/Admin/css/bootstrap-datetimepicker.css" rel="stylesheet">
<body>

<div id="wrapper">

    <!-- Navigation -->
    <include file="CommonSidebar:common-navbar"/>

    <div id="page-wrapper">
        <div class="row">
            <div class="col-md-12">
                <h1 class="page-header">用户管理</h1>
            </div>
        </div>

        <!-- /.row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">

                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <div class="dataTable_wrapper">
                            <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                <include file="Extends/searchForUser"/>
                                <thead>
                                <tr>
                                    <th class="text-center GridSortTh" width="10%" data-order="num">编号</th>
                                    <th class="text-center" width="8%">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <foreach name="data" item="v">
                                    <tr>
                                        <td>{$v['order_id']}</td>
                                        <td>
                                            <a class="lock" href="javascript:void(0)"  data-openid='{$v.openid}' data-lock='{$v.lock}' title="lock">
                                                <if condition="$v['lock'] == 0">
                                                    <span class="text-danger">锁定</span>
                                                    <else/>
                                                    <span class="text-success">解锁</span>
                                                </if>
                                            </a>
                                        </td>
                                    </tr>
                                </foreach>
                                </tbody>
                            </table>
                            <div class="blue">{$show}</div>
                        </div>
                        <!-- /.table-responsive -->
                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
    </div>
    <!-- /#page-wrapper -->
</div>
<div id="NoteModal" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title text-center">备注</h4>
            </div>
            <div class="modal-body">
                <input type="hidden" class="form-control" id="remarkid" name="openid" value/>
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-xs-12">
                            <textarea style="height: 100px;resize: none;" class="form-control" id="remark" name="remark" placeholder ="请输入..."></textarea>
                        </div>
                    </div>

                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success btn-profit-ok btn-block updateNote">
                    确定
                </button>
            </div>
        </div>
    </div>
</div>
<include file="CommonSidebar:common-script"/>

<script src="__PUBLIC__/Admin/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
<script src="__PUBLIC__/Admin/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>
<script src="__PUBLIC__/Admin/js/bootstrap-datetimepicker.js"></script>
<script src="__PUBLIC__/Admin/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="__PUBLIC__/Common/grid.js"></script>
</body>
<script type="text/javascript">

    $('#dataTables-example').grid();

    $(function () {
        $('#startdate').datetimepicker({
            language:  'zh-CN',
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            minView: 2,
            forceParse: 0,
            format: 'yyyy-mm-dd'
        });
        $('#enddate').datetimepicker({
            language:  'zh-CN',
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            minView: 2,
            forceParse: 0,
            format: 'yyyy-mm-dd'
        });
    });

    $(document).on("click", "#resetSearch", function () {
        $(".searchInput").val('');
    });

    //锁定-解锁
    $(".lock").click(function(){
        var $elem = $(this);
        var openid = $elem.attr("data-openid");
        var lock = $elem.attr("data-lock");

        var str="";
        var newlock="";
        if(lock==1){
            str="确定解锁该用户？";
            newlock=0;
        }else{
            str="确定锁定该用户？";
            newlock=1;
        }
        layer.msg(str, {
            time: 5000 //不自动关闭
            ,btn: ['确定', '取消']
            ,yes: function(index){
                layer.close(index);
                $.ajax({
                    type: "POST",
                    url: "{:U('update')}",
                    data: {
                        openid: openid,
                        lock: newlock,
                    },
                    dataType: "json",
                    success: function (result) {
                        layer.msg(result.info);
                        if(result.state == "1"){
                            if(lock == 1){
                                $elem.attr("data-lock",0);
                                $elem.children("span").html("锁定");
                                $elem.children("span").removeClass("text-success").addClass("text-danger");
                            }else{
                                $elem.attr("data-lock",1);
                                $elem.children("span").html("解锁");
                                $elem.children("span").removeClass("text-danger").addClass("text-success");
                            }
                        }
                    },
                    error: function () {
                        layer.msg("网络连接失败！");
                    }
                });
            }
        });
    });

    $(document).on("click",".setNote",function (){
        var openid = $(this).attr('data-openid');
        var remark = $(this).prev('span').html();
        $("#remarkid").val(openid);
        $("#remark").val(remark);
        $("#NoteModal").modal();
    });

    $(document).on("click",".updateNote",function (){
        var openid = $("#remarkid").val();
        var remark = $("#remark").val();
        $.ajax({
            type: "POST",
            url: "{:U('update')}",
            data: {
                openid: openid,
                remark: remark
            },
            dataType: "json",
            success: function (result) {
                if(result.state == "1"){
                    $('.setNote[data-openid="'+openid+'"]').prev('span').html(remark);
                }else{
                    layer.msg("编辑失败！");
                }
                $("#NoteModal").modal('hide');
            },
            error: function () {
                layer.msg('网络连接失败！');
            }
        });
    });
</script>
</html>
